Skip to content

feat: add stats/strided/selmax#11701

Draft
iampratik13 wants to merge 2 commits intostdlib-js:developfrom
iampratik13:feat/add-stats-strided-selmax
Draft

feat: add stats/strided/selmax#11701
iampratik13 wants to merge 2 commits intostdlib-js:developfrom
iampratik13:feat/add-stats-strided-selmax

Conversation

@iampratik13
Copy link
Copy Markdown
Member

@iampratik13 iampratik13 commented Apr 21, 2026

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • feat: add stats/strided/selmax

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • none

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

@iampratik13 iampratik13 requested a review from a team April 21, 2026 18:50
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Apr 21, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Apr 21, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/strided/selmax $\color{green}328/328$
$\color{green}+0.00%$
$\color{green}44/44$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}328/328$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@iampratik13
Copy link
Copy Markdown
Member Author

/stdlib merge

@stdlib-bot stdlib-bot added bot: In Progress Pull request is currently awaiting automation. and removed bot: In Progress Pull request is currently awaiting automation. labels Apr 21, 2026
@iampratik13
Copy link
Copy Markdown
Member Author

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added bot: In Progress Pull request is currently awaiting automation. and removed bot: In Progress Pull request is currently awaiting automation. labels Apr 21, 2026
@kgryte kgryte added Feature Issue or pull request for adding a new feature. difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. review: 5 and removed Needs Review A pull request which needs code review. labels Apr 23, 2026
/**
* Mask array.
*/
type MaskArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct. For the "generic" API, we simply mask based on truthiness.

Suggested change
type MaskArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
type MaskArray = Collection<unknown> | AccessorArrayLike<unknown>;

selmax( x.length, x, ( x: number ): number => x, mask, 1 ); // $ExpectError
}

// The compiler throws an error if the function is provided a fourth argument which is not a numeric array...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The compiler throws an error if the function is provided a fourth argument which is not a numeric array...
// The compiler throws an error if the function is provided a fourth argument which is not an array...

selmax.ndarray( x.length, x, 1, ( x: number ): number => x, mask, 1, 0 ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array...
// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not an array...

strideX: integer
Stride length for `x`.

mask: Array<number>|TypedArray
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mask: Array<number>|TypedArray
mask: Array|TypedArray

offsetX: integer
Starting index for `x`.

mask: Array<number>|TypedArray
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mask: Array<number>|TypedArray
mask: Array|TypedArray

* @param {PositiveInteger} N - number of indexed elements
* @param {NumericArray} x - input array
* @param {integer} strideX - `x` stride length
* @param {NumericArray} mask - mask array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {NumericArray} mask - mask array
* @param {Collection} mask - mask array

* @param {NumericArray} x - input array
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {NumericArray} mask - mask array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {NumericArray} mask - mask array
* @param {Collection} mask - mask array

Comment on lines +80 to +82
var mask0 = new BooleanArray([
true, true, true, true, true, true, false, false
]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var mask0 = new BooleanArray([
true, true, true, true, true, true, false, false
]);
var mask0 = new BooleanArray( [ true, true, true, true, true, true, false, false ] );

No splitting over multiple lines like this.


Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- eslint-disable stdlib/capitalized-comments -->
<!-- eslint-disable stdlib/capitalized-comments, max-len -->

Comment on lines +163 to +170

* * *

## See Also

- <span class="package-name">[`@stdlib/stats/strided/max`][@stdlib/stats/strided/max]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array.</span>
- <span class="package-name">[`@stdlib/stats/strided/mskmax`][@stdlib/stats/strided/mskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array according to a mask.</span>
- <span class="package-name">[`@stdlib/stats/strided/nanmax`][@stdlib/stats/strided/nanmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array, ignoring NaN values.</span>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * *
## See Also
- <span class="package-name">[`@stdlib/stats/strided/max`][@stdlib/stats/strided/max]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array.</span>
- <span class="package-name">[`@stdlib/stats/strided/mskmax`][@stdlib/stats/strided/mskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array according to a mask.</span>
- <span class="package-name">[`@stdlib/stats/strided/nanmax`][@stdlib/stats/strided/nanmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array, ignoring NaN values.</span>

Comment on lines +188 to +193
[@stdlib/stats/strided/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/max

[@stdlib/stats/strided/mskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/mskmax

[@stdlib/stats/strided/nanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/nanmax

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[@stdlib/stats/strided/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/max
[@stdlib/stats/strided/mskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/mskmax
[@stdlib/stats/strided/nanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/nanmax

Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part, this is coming along. One thing that should be changed throughout is that mask should be a boolean array. So, instead of

var mask = bernoulli( x.length, 0.8, {
    'dtype': 'generic'
});

do

var mask = new BooleanArray( bernoulli( x.length, 0.8 ) );

Instead of

var mask = [ 1, 1, 0, 1 ];

do

var mask = [ true, true, false, true ];

Otherwise, your text which states that an element is only considered valid if a mask element is true is inconsistent with the examples, which are primarily showing numeric arrays.

It is fine, if operationally within this package, we accept non-boolean arrays, but all of our examples and docs should use boolean arrays or generic arrays containing booleans in order to communicate user expectation.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. review: 2 and removed review: 5 labels Apr 23, 2026
@iampratik13 iampratik13 force-pushed the feat/add-stats-strided-selmax branch from 454641e to 6f347cc Compare April 25, 2026 06:35
@iampratik13 iampratik13 marked this pull request as draft April 25, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. review: 2 Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants